﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO_HealthInsurance;
namespace DAO_HealthInsurance
{
  public  class DAOPolicyTotalDes:ConnectDatabase
    {
        public SqlCommand Cmd;
        public DTOPolicyTotalDescription objPoToDes;
        public DataTable ListPoToDes()
        {
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("ListPoToDes", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("PolicyTotalDescription");
                da.Fill(dt);
                CloseConnect();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public int InsertPoToDes(DTOPolicyTotalDescription objPoToDes)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("InsertPoToDes", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoToDes.PolicyId;
                Cmd.Parameters.Add("@PolicyName", SqlDbType.VarChar,50).Value = objPoToDes.PolicyName;
                Cmd.Parameters.Add("@PolicyDes", SqlDbType.VarChar,250).Value = objPoToDes.PolicyDes;
                Cmd.Parameters.Add("@PolicyAmount", SqlDbType.Float).Value = objPoToDes.PolicyAmount;
                Cmd.Parameters.Add("@Emi", SqlDbType.Float).Value = objPoToDes.PolicyEmi;
                Cmd.Parameters.Add("@PolicyDurationMonths", SqlDbType.Int).Value = objPoToDes.PolicyDurationMonth;
                Cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50).Value = objPoToDes.PolicyName;
                Cmd.Parameters.Add("@MedicalId", SqlDbType.VarChar, 50).Value = objPoToDes.MedicalId;
                


                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;
        }

        public int DeletePoToDes(DTOPolicyTotalDescription objPoToDes)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("DeletePoToDes", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoToDes.PolicyId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }
        public int UpdatePoToDes(DTOPolicyTotalDescription objPoToDes)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("UpdatePoToDes", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoToDes.PolicyId;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoToDes.PolicyId;
                Cmd.Parameters.Add("@PolicyName", SqlDbType.VarChar, 50).Value = objPoToDes.PolicyName;
               
                Cmd.Parameters.Add("@PolicyAmount", SqlDbType.Float).Value = objPoToDes.PolicyAmount;
                Cmd.Parameters.Add("@Emi", SqlDbType.Float).Value = objPoToDes.PolicyEmi;
                Cmd.Parameters.Add("@PolicyDurationMonths", SqlDbType.Int).Value = objPoToDes.PolicyDurationMonth;
                Cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50).Value = objPoToDes.PolicyName;
                Cmd.Parameters.Add("@MedicalId", SqlDbType.VarChar, 50).Value = objPoToDes.MedicalId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }

        public DataTable GetPoToDesByPoId(DTOPolicyTotalDescription objPoToDes)
        {
            try
            {
                Cmd = new SqlCommand("GetPoToDesByPoId", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoToDes.PolicyId;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("PolicyTotalDescription");
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
